<?php
session_start();
cls_General_Forms::code_block_starts('');

//echo 'this is the content of the center';
 #########################################################################  
$blocked = security::head_entry();
  if($blocked){      
  #Form to be loaded in case no post or request has been made		
    if(!isset($_POST['submit']) && !isset($_SESSION['username']) && !isset($_REQUEST['action'])){  
       cls_General_Forms::login_form();  
        #get all the users for display
        
                      // $user_type=admin_functions::get_users();
                       #display the adding form
                      // admin_forms::add_user($user_type);
                     
        }else{
            if(isset($_REQUEST['action'])=="admission" && (!isset($_SESSION['username']))){
                    if($_REQUEST['spec']=="add"){
                        #get the courses,religion and satus from dbase
                        $status = admin_functions::get_status_admission();
                        $religion = admin_functions::get_religion();
                        $course = admin_functions::get_courses_option();
                        #show the pre-enrollment form
                        admission_forms::log_profile($course,$religion,$status);
                    }
            }  
           // echo "<center style='font-size:24pt';>Welcome to SSC Student Information System</center>";
        }
  }else{
      die("<p class='warnings'>This address is temporarily closed due to successive failed login attempts</p>");
  }
#this will be the processing part of posts and requests
if(isset($_POST['submit'])){
    switch($_POST['submit']){

            case 'LOGIN':
                    #this will check validity of credentials if  true
                    $profile=admin_functions::check_user_profile($_POST['username'],$_POST['password'],$_POST['profile_id']);  
                        if($profile){                               
                              #this will reset the counter of the ip
                              $_SESSION['page']="Home";  
                              header('location:main.php');
                        }else{
                            die("<p class='warnings'>Invalid user credentials!</p>");
                        }           
                            
                
                break;   
                
                 case 'Update User':
                    #add a user
                    $_SESSION['username']= $_POST['username'];
                    admin_functions::add_edit_delete_users($_POST,"edit");
                    
                break;  
                
               case 'Apply Settings': 
                    #this function will override default settings for syear
                        admin_functions::setting_configure($_POST); 
                    break;        
                  
                case 'ADD EXAM':
                admin_functions::create_exam($_POST);
                    break; 
                    
                case 'ADD ITEMS':
                    admin_functions::add_items_dbase($_POST);
                    break; 
                    
                case 'TAKE EXAM':
                        #prepare algorithm for exam and create table
                         admin_functions::prepare_an_exam_now($_POST);
                        #get questions from created table
                        $items = admin_functions::get_questions_to_render($_POST); 
                        #show to form  the questions
                        admission_forms::render_questions($items,$_POST['student_id'],$_POST['exam_name']);
                         
                    break;
                    
                case 'DONE':
                       admin_functions::insert_answers($_POST);
                    break;                                                       
    }           
}

if(isset($_REQUEST['action']) && isset($_SESSION['username'])){
    switch($_REQUEST['action']){
          case 'logout':
           // admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
           admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
            session_destroy();
            header("location:main.php");
            break;
            
           case 'settings':
             #this will enable default settings to be changed
               $syear = miscellaneous::school_year();
               admin_forms::settings_config($syear);
                break;  
        
           
           case 'ask':
               if($_REQUEST['page']=="admission"){
                    if($_REQUEST['spec']=="add"){
                        #get the courses,religion and satus from dbase
                        $status = admin_functions::get_status_admission();
                        $religion = admin_functions::get_religion();
                        $course = admin_functions::get_courses_option();
                        #show the pre-enrollment form
                        admission_forms::log_profile($course,$religion,$status);
                    }elseif($_REQUEST['spec']=="view"){
                        #get the names from dbase
                         $names = admin_functions::get_admission_names();
                         #show the names as forms
                         admission_forms::show_admission_profile($names);
                    }elseif($_REQUEST['spec']=="question"){
                        #get create a new exam
                        admission_forms::entry_form_exam_new();                        
                    }elseif($_REQUEST['spec']=="additems"){
                        #get the list of exams
                        $names = admin_functions::get_exams_names();                        
                        admission_forms::add_items_exam($names);                      
                    }elseif($_REQUEST['spec']=="addquestion"){
                        #get the exams and choices
                        $row = admin_functions::get_items_choices($_REQUEST['subj']);
                         admission_forms::add_questions($row);
                    }elseif($_REQUEST['spec']=="takeexam"){
                        #show the exam to be taken
                            $names = admin_functions::get_exams_names();
                             admission_forms::show_exam_to_take($names);
                    }elseif($_REQUEST['spec']=="viewresult"){
                        #show the list and status of examinees
                        $names =  admin_functions::get_names_students();
                        #show the form of names
                        admission_forms::show_result_exam($names);
                    }   
               }elseif($_REQUEST['page']=="admin"){
                   if($_REQUEST['spec']=="add"){
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #display the adding form
                       admin_forms::add_user($user_type);
                   }elseif($_REQUEST['spec']=="view"){
                        #get all the data to view
                       $data=admin_functions::get_users_profile();
                        admin_forms::view($data);
                   }elseif($_REQUEST['spec']=="delete"){
                       #this will delete the user from user_profile
                       $data=array('username'=>$_REQUEST['username']);
                       admin_functions::add_edit_delete_users($data,"delete");
                   }else{
                        #this will edit the user from user_profile
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #get records
                       $records=admin_functions::get_specific_profile($_SESSION['username']);
                       #display the adding form
                       admin_forms::edit_user($user_type,$records);
                   }
            }
               break;
                     
    }  

}
 ###############################################################################       
cls_General_Forms::code_block_ends();
?>